import { useEquip } from "@/stores/useEquip";
import { adjustAIParse, aoModbusRegParse } from "@/utils/parse";
import { ModbusReg } from "../types/SocketData";

export const handleModbusReg = (modbusRegData: ModbusReg) => {
    const equipStore = useEquip();
    if (modbusRegData.regstart >= 12000 && modbusRegData.regstart <= 18420) {
        // 智能自控
    } else if (modbusRegData.regstart == 1004) {
        // 变化回传
        if (modbusRegData.code == 3) console.log(modbusRegData);
    } else if (modbusRegData.regstart == 1010) {
        // 掉电保存
        if (modbusRegData.code == 3) console.log(modbusRegData);
    } else if (modbusRegData.regstart == 3300) {
        // AI校准3
        if (modbusRegData.code == 3) {
            equipStore.adjustAIComputed({ funid: modbusRegData.sn, adjustAI: adjustAIParse(modbusRegData) });
        }
    } else if (modbusRegData.code == 3) {
        // ao
        equipStore.equipRegDataComputed({ funid: modbusRegData.sn, online: true, regAO: aoModbusRegParse(modbusRegData) });
    }
};
